package com.yyj.controller;

import com.github.pagehelper.PageInfo;
import com.yyj.entity.Params;
import com.yyj.entity.Reserve;
import com.yyj.entity.Result;
import com.yyj.entity.TimeSelection;
import com.yyj.service.ReserveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/reserve")
public class ReserveController {
    @Autowired
    private ReserveService reserveService;

    //insert 用户创建预约
    @PostMapping("/establish")
    public Result establish(@RequestBody Reserve reserve) {
        reserveService.establish(reserve);
        return Result.success();
    }

    @GetMapping("/{doctorName}")
    public Result getNum(@PathVariable String doctorName) {
        List<TimeSelection> list = reserveService.getNum(doctorName);
        return Result.success(list);
    }

    //兽医查询自己的预约信息
    @GetMapping("/getOwnReserve")
    public Result getReserve(Params params) {
        PageInfo<Reserve> info = reserveService.getReserve(params);
        return Result.success(info);
    }

    //用户查看自己的预约信息
    @GetMapping("/getApplication/{userName}")
    public Result getApplication(@PathVariable String userName) {
        List<Reserve> list = reserveService.getApplication(userName);
        return Result.success(list);
    }


    //设置金额 修改进程
    @PostMapping("/setPrice")
    public Result setPrice(@RequestBody Reserve reserve) {
        reserveService.setPrice(reserve);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        reserveService.delete(id);
        return Result.success();
    }

}
